package com.itheima.day14;

import java.io.*;
import java.util.*;

public class Practice2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        TreeMap<String, ArrayList<Student>> map = new TreeMap<>();
        ArrayList<Student> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {

            System.out.println("请输入第"+(i+1)+"学生的姓名");
            String name = sc.next();
            System.out.println("请输入第"+(i+1)+"学生的语文成绩：");
            int yuWen = sc.nextInt();
            System.out.println("请输入第"+(i+1)+"学生的数学成绩：");
            int shuXue = sc.nextInt();
            System.out.println("请输入第"+(i+1)+"学生的英语成绩：");
            int yingYu = sc.nextInt();
            Student student =new Student(yuWen,shuXue,yingYu);
            list.add(student);
            map.put(name,list);
        }

        try (FileOutputStream fos = new FileOutputStream("D:\\code\\javaee156\\javaeezuoye\\src\\com\\itheima\\day14\\students.txt");
             DataOutputStream dos = new DataOutputStream(fos);
        ){
            for (Map.Entry<String, ArrayList<Student>> entry : map.entrySet()) {
                for (int i = 0; i < 3; i++) {
                    StringBuilder sb =new StringBuilder();
                   //  sb.append("请录入第"+(i+1)+"个学生的信息：\r\n");

                    // sb.append("姓名：\r\r");

                  //  sb.append(entry.getKey()+"\r\n");
//                     sb.append("语文成绩：\r\n");
//                    sb.append(entry.getValue().get(0).getYuWen()+"\r\n");
//                     sb.append("数学成绩：\r\n");
//                    sb.append(entry.getValue().get(1).getShuXue()+"\r\n");
//                   sb.append("英语成绩：\r\n");
//                    sb.append(entry.getValue().get(2).getYingYu());
//                    //System.out.println(sb);
                    sb.append(entry.getKey()).append(entry.getValue());


                    String s = sb.toString();

                    dos.writeUTF(s);


                }
            }

        }  catch (IOException e) {
            e.printStackTrace();
        }
map.forEach((s, students) -> System.out.println(s+students));
        }
    }

class Student implements Comparable<Student>{

    private int yuWen;
    private  int shuXue;
    private  int yingYu;

    public Student() {
    }

    public Student(  int yuWen, int shuXue, int yingYu) {

        this.yuWen = yuWen;
        this.shuXue = shuXue;
        this.yingYu = yingYu;
    }

    @Override
    public int compareTo(Student o) {
        return (o.getShuXue()+o.getYingYu()+o.getYuWen())-(this.getShuXue()+this.getYingYu()+this.getYuWen());
    }




    public int getYuWen() {
        return yuWen;
    }

    public void setYuWen(int yuWen) {
        this.yuWen = yuWen;
    }

    public int getShuXue() {
        return shuXue;
    }

    public void setShuXue(int shuXue) {
        this.shuXue = shuXue;
    }

    public int getYingYu() {
        return yingYu;
    }

    public void setYingYu(int yingYu) {
        this.yingYu = yingYu;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return yuWen == student.yuWen && shuXue == student.shuXue && yingYu == student.yingYu    ;
    }

    @Override
    public int hashCode() {
        return Objects.hash(  yuWen, shuXue, yingYu);
    }

    @Override
    public String toString() {
        return

                  yuWen +
                ", " + shuXue +
                ", " + yingYu
                 ;
    }
}